
const render_mapper = {
    bind_page: [],
    mapper_event : {},
    getConnect() {
        this.webSocket = new WebSocket("ws://127.0.0.1:8000/code/");
        this.webSocket.onmessage = this.recvMessage;
        this.webSocket.onclose = (event) => {
            // TODO 角色退出游戏
            console.log("离开链接")
        }
        this.webSocket.addEventListener('open', function () {
            console.log('WebSocket连接已建立');
            // console.log(this)
            this.send("你好")
        });
    },

    recvMessage(event) {
        console.log(event.data)
        let data;
        try {
            data = JSON.parse(event.data)
        } catch (e) {
            data = event.data
            console.log(data)
            return
        }
        console.log(this.mapper_event)
        render_mapper.mapper_event[data.messge_mod](data)
    },
    send(mesg) {
        console.log("开始发送")
        setTimeout(() => {
            this.webSocket.send(mesg)
            return
        }, 1000)

    }

}


export default render_mapper